db = db.getSiblingDB('SmartParker');
//获取当前毫秒数
var t = new Date().getTime()

//确保索引
if(db['comment_queue'].count() == 0) {
    db['comment_queue'].ensureIndex({'cid':1})
    db['comment_queue'].ensureIndex({'stat':1})
}

var i = 0;
//每次最多保存1000个
while(i < 1000) {
    var record = db['comment_queue'].findAndModify({'query':{'status':0,'timestamp':{'$lt':t}},'update':{'status':-1}})
    if(!record) {
        break;
    }
    var comment = record.comment
    db['comment'].save(comment)
    print(comment.cid)   
    ++i;     
}
print("保存" + i + '个对象');
